package pt.compflow;

import pt.compflow.flowontology.model.Activity;
import pt.compflow.flowontology.model.Event;
import pt.compflow.flowontology.model.FlowOntologyModel;
import pt.compflow.flowontology.model.Gateway;
import pt.compflow.flowontology.model.Job;
import pt.compflow.flowontology.model.Task;
import pt.compflow.flowontology.model.Workflow;
import pt.compflow.tools.OntModelHelper;

import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.Resource;

/**
 * This class aids the Workflow Engine with the instantiation of Workflow components
 * and handling/generation of unique identifiers
 * 
 * @author Nuno Luz
 *
 */
public interface Instantiator {

	/**
	 * Creates a Workflow-Definition instance for a given job, inside the given jobModel
	 * @param ontModel - the ontology model containing the definition of the workflow
	 * @param jobModel - the model that will contain the instantiation of the workflow-definition 
	 * @param engineModel - the engine model
	 * @param clazz - the class of the workflow (the workflow-definition)
	 * @param parentWf - the parent workflow (optional)
	 * @param job - the job
	 * @return - the workflow instance
	 */
	public Workflow getWorkflowInstance(OntModelHelper ontModelHelper, FlowOntologyModel jobModel, FlowOntologyModel engineModel, Resource clazz, Workflow parentWf, Job job);
	
	/**
	 * Creates a Task-Definition instance for a given workflow, inside the given jobModel
	 * @param ontModel - the ontology model containing the definition of the workflow
	 * @param jobModel - the model that will contain the instantiation of the task-definition 
	 * @param engineModel - the engine model
	 * @param clazz - the class of the task (the task-definition)
	 * @param wf - the workflow containing this task
	 * @return the task instance
	 */
	public Task getTaskInstance(OntModelHelper ontModelHelper, FlowOntologyModel jobModel, FlowOntologyModel engineModel, Resource clazz, Workflow wf);
	
	/**
	 * Creates a Gateway-Definition instance for a given workflow, inside the given jobModel
	 * @param ontModel - the ontology model containing the definition of the workflow
	 * @param jobModel - the model that will contain the instantiation of the gateway-definition 
	 * @param engineModel - the engine model
	 * @param clazz - the class of the gateway (the gateway-definition)
	 * @param wf - the workflow containing this gateway
	 * @return the gateway instance
	 */
	public Gateway getGatewayInstance(OntModelHelper ontModelHelper, FlowOntologyModel jobModel, FlowOntologyModel engineModel, Resource clazz, Workflow wf);
	
	/**
	 * Creates an Event-Definition instance for a given workflow, inside the given jobModel
	 * @param ontModel - the ontology model containing the definition of the workflow
	 * @param jobModel - the model that will contain the instantiation of the event-definition 
	 * @param engineModel - the engine model
	 * @param clazz - the class of the event (the event-definition)
	 * @param wf - the workflow containing this event
	 * @return the event instance
	 */
	public Event getEventInstance(OntModelHelper ontModelHelper, FlowOntologyModel jobModel, FlowOntologyModel engineModel, Resource clazz, Workflow wf);
	
	/**
	 * Creates an Activity-Definition (Workflow, Task, Gateway or Event) instance for a given workflow and job, inside the given jobModel
	 * @param ontModel - the ontology model containing the definition of the workflow
	 * @param jobModel - the model that will contain the instantiation of the activity-definition 
	 * @param engineModel - the engine model
	 * @param clazz - the class of the activity (the activity-definition)
	 * @param wf - the workflow containing this activity (optional for workflow instantiations)
	 * @param job - the job containing this activity
	 * @return the activity instance
	 */
	public Activity getActivityInstance(OntModelHelper ontModelHelper, FlowOntologyModel jobModel, FlowOntologyModel engineModel, Resource clazz, Workflow wf, Job job);
	
	/**
	 * Returns an Unique Job Id (URI) inside the given Model (namespace not included)
	 * @param model - the model of the job
	 */
	public String getUniqueJobId(Model model);
	public String getUniqueJobTemplateId(Model model);
	
	/**
	 * Returns an Unique Workflow Id (URI) inside the given Model (namespace not included)
	 * @param model - the model of the workflow
	 * @param job - optional parent job of the workflow (to be considered in the URI)
	 */
	public String getUniqueWorkflowId(Model model, Job job);
	
	/**
	 * Returns an Unique Task Id (URI) inside the given Model (namespace not included)
	 * @param model - the model of the task
	 * @param job - optional parent job of the task (to be considered in the URI)
	 * @param wf - optional parent workflow of the task (to be considered in the URI)
	 */
	public String getUniqueTaskId(Model model, Job job, Workflow wf);
	
	/**
	 * Returns an Unique Gateway Id (URI) inside the given Model (namespace not included)
	 * @param model - the model of the gateway
	 * @param job - optional parent job of the gateway (to be considered in the URI) 
	 * @param wf - optional parent workflow of the gateway (to be considered in the URI)
	 */
	public String getUniqueGatewayId(Model model, Job job, Workflow wf);
	
	/**
	 * Returns an Unique Event Id (URI) inside the given Model (namespace not included)
	 * @param model - the model of the event
	 * @param job - optional parent job of the event (to be considered in the URI) 
	 * @param wf - optional parent workflow of the event (to be considered in the URI)
	 */
	public String getUniqueEventId(Model model, Job job, Workflow wf);
	
	/**
	 * Returns an Unique Activity Id (URI) inside the given Model (namespace not included)
	 * @param model - the model of the activity
	 * @param job - optional parent job of the activity (to be considered in the URI) 
	 * @param wf - optional parent workflow of the activity (to be considered in the URI)
	 */
	public String getUniqueActivityId(Model model, Job job, Workflow wf);
	
	/**
	 * Returns an Unique Assignment Id (URI) inside the given Model (namespace not included)
	 * @param model - the model of the assignment
	 * @param job - optional parent job of the assignment (to be considered in the URI) 
	 * @param wf - optional parent workflow of the assignment (to be considered in the URI)
	 * @param task - optional parent task of the assignment (to be considered in the URI)
	 */
	public String getUniqueAssignmentId(Model model, Job job, Workflow wf, Task task);
		
	/**
	 * Returns an Unique Resource Id (URI) inside the given Model (namespace not included)
	 * @param id - prefix of the id
	 * @param model - the model of the resource
	 */
	public String getUniqueId(String id, Model model);
}
